package View;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import Controller.EditAccount;



@SuppressWarnings("serial")
public class PanelEditAccount extends JPanel {

	private static PanelEditAccount single;

	private JLabel formName = new JLabel("Rekening toevoegen");
	private JLabel accountNumber = new JLabel("IBAN : ");
	private JLabel accountType = new JLabel("Rekening type : ");

	private JLabel accountName = new JLabel("Rekening beschrijving : ");
	private JLabel accountRent = new JLabel("Rekening rente : ");
	private JLabel accountAmount = new JLabel("Huidige saldo van rekening : ");

	private JTextField accountNumberField = new JTextField();
	private JTextField accountTypeField = new JTextField();
	private JTextField accountNameField = new JTextField();
	private JTextField accountRentField = new JTextField();
	private JTextField accountAmountField = new JTextField();

	private JButton confirmButton = new JButton("Opslaan");
	private JButton terugButton = new JButton("terug");

	public PanelEditAccount() {

		EditAccount edit = new EditAccount(this);

		setLayout(null);
		setBounds(140, 0, 860, 725);

		formName.setBounds(100, 30, 400, 30);
		formName.setFont(new Font("Serif", Font.BOLD, 20));

		accountNumber.setBounds(80, 70, 200, 30);
		accountType.setBounds(80, 110, 200, 30);
		accountName.setBounds(80, 150, 200, 30);
		accountRent.setBounds(80, 190, 200, 30);
		accountAmount.setBounds(80, 230, 200, 30);

		accountNumberField.setBounds(300, 70, 200, 30);
		accountTypeField.setBounds(300, 110, 200, 30);
		accountNameField.setBounds(300, 150, 200, 30);
		accountRentField.setBounds(300, 190, 200, 30);
		accountAmountField.setBounds(300, 230, 200, 30);

		confirmButton.setBounds(91, 289, 100, 30);
		confirmButton.setActionCommand("Opslaan");
		confirmButton.addActionListener(edit);

		terugButton.setBounds(320, 289, 110, 30);
		terugButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				PanelHolder mf = PanelHolder.getInstance();
				mf.remove(PanelEditAccount.getInstance());
				mf.add(PanelAccountDetail.getInstance());
				mf.repaint();
				mf.validate();
			}
		});

		add(formName);
		add(accountNumber);
		add(accountType);
		add(accountName);
		add(accountRent);
		add(accountAmount);

		add(accountNumberField);
		add(accountTypeField);
		add(accountNameField);
		add(accountRentField);
		add(accountAmountField);

		add(confirmButton);
		add(terugButton);

	}

	public static PanelEditAccount getInstance() {
		if (single == null) {
			single = new PanelEditAccount();
		}
		return single;
	}

	public static void selfDestroy() {
		single = null;
	}
}
